<template>
    <div class="userinfo">
        <h-header lftext="取消" title="设置昵称" @dele="confirm" delet="确定"></h-header>
        <div class="item-lr mt" style="padding-top: 0;padding-bottom: 0;padding-right: 15px;">
            <div class="left flex_one"><input type="text" placeholder="请输入昵称" v-model="nickname"></div>
            <div class="right"><i @click="deletetext()" style="font-size: 30px;" class="iconfont">×</i></div>
        </div>
        <div class="popup-container">
            <mt-popup
              v-model="popupVisible"
              position="top"
              :modal="modal">
              {{popupContent}}
            </mt-popup>
        </div>
    </div>
</template>

<script>
import Header from '../common/header';
import axios from 'axios';
import Wx from 'weixin-js-sdk';
import { MessageBox, Toast, Popup } from 'mint-ui';
import { setTimeout } from 'timers';
export default {
    data () {
        return {
            nickname: '',
            popupContent: '',
            modal: false,
            popupVisible: false,
        }
    },
    components: {
        'h-header': Header,
         'mt-popup': Popup,  
    },
    created () {
        const vm = this;
        axios.post('/Weixin/Member/memberDetail',{}).then(res=>{
            const data = res.data;
            if(data.code==1){
                vm.nickname= data.data.nickname;
            }else {
                MessageBox.alert(data.msg)
            }
        }).catch(()=>{
            MessageBox.alert('网络错误');
        })
    },
    mounted() {
        const vm = this;
        let url = window.location.href;
        vm.wxShare(url);
    },
    methods: {
        deletetext(){
            const vm = this;
            vm.nickname = '';
        },
        confirm(){
            const vm = this;
            if( vm.nickname==''){
               vm.popupVisible = true;
                vm.modal = true;
                vm.popupContent = '昵称不能为空';
                setTimeout(function(){
                    vm.popupVisible = false;
                },1600);
               return;
            }
            let data = {
                nickname: vm.nickname
            };
            axios.post('/Weixin/Member/editMember', data).then(res => {
                console.log(res);
                const data = res.data;
                if (data.code == 1) {
                    vm.$router.replace('/userinfo');
                }
                this.$toast(data.msg);
            });
        }
    }
}
</script>

<style>

</style>
